package org.ezplatform.office.forum.web.rest;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.ezplatform.core.pagination.PropertyFilter;
import org.ezplatform.core.service.BaseService;
import org.ezplatform.core.web.controller.BaseController;
import org.ezplatform.office.forum.entity.ForumIntegralRecord;
import org.ezplatform.office.forum.service.ForumIntegralRecordService;
import org.ezplatform.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 论坛积分规则控制类
 * 2020年09月22日17:40:59
 * @author Administrator
 *
 */
@RestController
@RequestMapping(value = "/api/w/forum/integralrecord")
public class ForumIntegralRecordWebApiController extends BaseController<ForumIntegralRecord, String> {
	
    private final Logger log = LoggerFactory.getLogger(ForumIntegralRecordWebApiController.class);
    
    @Autowired
    private ForumIntegralRecordService forumIntegralRecordService;

    @Override
    protected BaseService<ForumIntegralRecord, String> getEntityService() {
        return forumIntegralRecordService;
    }
    
    /**
     * 初始化数据
     * @param request
     * @param model
     * @param id
     */
    @ModelAttribute
    public void prepareModel(HttpServletRequest request, Model model,
                             @RequestParam(value = "id", required = false) String id) {
        super.initPrepareModel(request, model, id);
    }
    
    /**
     * 获取积分扣减记录列表数据(分页)
     * @return
     */
    @SuppressWarnings("rawtypes")
	@RequestMapping(value = "/getInfoPage", method = RequestMethod.GET)
    @ResponseBody
    public Page<Map> getInfoPage(HttpServletRequest request) {
    	Pageable pageable = PropertyFilter.buildPageableFromHttpRequest(request);
    	List<PropertyFilter> buildFilters = PropertyFilter.buildFiltersFromHttpRequest(ForumIntegralRecord.class, request);   	
    	String type = StringUtils.null2String(request.getParameter("type"));
    	String startTime = "";
		String endTime = "";
    	if("user".equals(type)) {
    		startTime = StringUtils.null2String(request.getParameter("startTime"));
    		endTime = StringUtils.null2String(request.getParameter("endTime"));
    	}else {
    		startTime = StringUtils.null2String(request.getParameter("startTime_all"));
    		endTime = StringUtils.null2String(request.getParameter("endTime_all"));
    	}
    	Page<Map> page = forumIntegralRecordService.findByPage(pageable, buildFilters,type,startTime,endTime);    	
    	return page;
    }
    
}